<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<%
	//检查会话中是否有 "student" 属性
	Object fdyObj = session.getAttribute("student");
	if (fdyObj == null) {
	    response.sendRedirect("../view/Login.jsp");
	    return;
	}
%>
    
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>学生页面</title>
<link href="../css/Utils.css" rel="stylesheet" type="text/css" />
<link href="../css/List.css" rel="stylesheet" type="text/css" />
<!-- 退出登录专用 -->
   <script type="text/javascript" src="../view/Loginout.js"></script>
</head>
<body>

<!-- 头部 -->
<div class="header" ><br>
<nerong>&nbsp;&nbsp;学生页面&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;</nerong>

 <button onclick="confirmLogout('<%= (String)session.getAttribute("student") %>','student')">退出登录</button>

</div><br>

<div class="left" >
<table width="80%" height="80%">
<th>
<nerong>学生可选择内容</nerong>

</th>


<tr>
<td>
<a href="../View_Msg/msgStudent.jsp">&emsp;个人信息</a><br>
</td>
</tr>

<tr>
<td>
<a href="../View_SuShe/SuSheStudent.jsp">&emsp;宿舍信息</a><br>
</td>
</tr>

<tr>
<td>
<a href="../View_fix/StudentFix.jsp">&emsp;宿舍报修</a><br>
</td>
</tr>

<tr>
<td>
<a href = "../View_WeiGui/WeiGuiStudent.jsp">&emsp;违规消息查询</a><br>
</td>
</tr>

<tr>
<td>
<a href = "S_Main_Leave.jsp">&emsp;请假</a><br>
</td>
</tr>


</table>

</div>


<div class="context" >
<!-- 这部分是每个大功能的小功能 -->

	<form action="../LeaveServlet" method="post">

        <h2 align = "center">新增请假申请</h2>
        
        
            <!-- 请假编号（自动生成，用户不能修改） -->
            
                <label for="leave-id">请假编号：</label>
                <input type="text" id="leave-id" name="number" readonly style="background-color: #d3d3d3;">
                <!-- 使用JavaScript生成请假编号 -->
                <script>
                    document.getElementById('leave-id').value = 'LEAVE-' + Math.floor(100000 + Math.random() * 900000);
                </script>
            
 
 
 		<div style="display: flex; justify-content: space-between;">
			<!-- 学号 -->
			
    			<label for="student-id">学号：</label>
    			<input type="text" id="student-id" name="id" required>
			
			
			<!-- 班级 -->
			
    			<label for="student-id">班级：</label>
    			
    			<select id="student-id" name="classroom" >
                    <option value="">--请选择班级--</option>
                    <option value="0101">--0101班--</option>
                    <option value="0102">--0102班--</option>
                    <option value="0201">--0201班--</option>
                    <option value="0301">--0301班--</option>
                </select>
			
			
			<!-- 姓名 -->
			
    			<label for="name-input">姓名：</label>
    			<input type="text" id="name-input" name="name" required>
			
			</div>
 
 			<!-- 课程 -->
 			<div class="form-group">
                <label for="class-select">选择课程：</label>
                <select id="class-select" name="course">
                    <option value="">--请选择课程--</option>
                    <option value="猫咪语言教学">--猫咪语言教学--</option>
                    <option value="地下生物烹饪学">--地下生物烹饪学--</option>
                    <option value="标本制作基础">--标本制作基础--</option>
                    <option value="手风琴基础修养">--手风琴基础修养--</option>
                </select>
            </div>
 
            <!-- 请假开始日期和结束日期 -->
            <div class="form-group">
                <label>请假开始日期：</label>
                <input type="date" id="start-date" name="sdata" required>
            </div>
            <div class="form-group">
                <label>请假结束日期：</label>
                <input type="date" id="end-date" name="edate" required>
                <!-- 使用JavaScript计算请假天数 -->
                <script>
                    document.getElementById('end-date').addEventListener('input', function() {
                        const startDate = new Date(document.getElementById('start-date').value);
                        const endDate = new Date(document.getElementById('end-date').value);
                        const diffInTime = endDate.getTime() - startDate.getTime();
                        const diffInDays = diffInTime / (1000 * 3600 * 24);
                        document.getElementById('leave-days').value = diffInDays;
                    });
                </script>
            </div>
            <div class="form-group" >
                <label>请假天数：</label>
                <input type="text" id="leave-days" name="sumdata" readonly style="background-color: #d3d3d3;">
            </div>
 
 
 			<!-- 联系方式（必须为11位数字） -->
			<div class="form-group">
    			<label for="contact">联系方式：</label>
    			<input type="tel" id="contact" name="phone" required pattern="\d{11}" title="请输入11位数字作为联系方式">
			</div>
 
            <!-- 请假事由 -->
            <div class="form-group">
                <label for="leave-reason">请假事由（不少于10字）：</label>
                <textarea id="leave-reason" name="reason" rows="4" required minlength="10" value="不少于10字"></textarea>
            </div>
 
            <!-- 是否出校 -->
            <div >
                <p>是否出校：</p>
                <label><input type="radio" name="go" value="是" onclick="toggleOutingAddress()"> 是</label>
                <label><input type="radio" name="go" value="否" onclick="toggleOutingAddress()"> 否</label>
            </div>
 
            <!-- 出校去向地址（根据是否出校显示/隐藏） -->
            <div class="form-group" id="outing-address-group" class="hidden">
                <label for="outing-address">出校去向地址：</label>
                <input type="text" id="outing-address" name="address">
            </div>
 
            <!-- 提交按钮 -->
            <button type="submit">提交申请</button>
        </div>
        </form>
    
 
 
    <script>
        // 初始隐藏出校去向地址
        document.getElementById('outing-address-group').classList.add('hidden');
 
        // 根据是否出校的选择显示或隐藏出校去向地址
        function toggleOutingAddress() {
            const outingAddressGroup = document.getElementById('outing-address-group');
            const leaveCampusRadios = document.getElementsByName('go');
            for (const radio of leaveCampusRadios) {
                if (radio.checked && radio.value === '否') {
                    outingAddressGroup.classList.add('hidden');
                    document.getElementById('outing-address').value = ''; // 清空地址
                } else if (radio.checked && radio.value === '是') {
                    outingAddressGroup.classList.remove('hidden');
                }
            }
        }
 
        // 页面加载时检查默认选中的选项
        window.onload = function() {
            toggleOutingAddress();
        };
    </script>

</body>
</html>